package com.mj.mes.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * author : cRyann
 *
 * @create 2017-09-19
 **/
public final class FileUtils {
    public FileUtils() {
    }

    public static File copeMultipartFile(MultipartFile from, String to) {
        File f = new File(to + from.getOriginalFilename());
        if (!f.exists()) {
            try {
                File dir = new File(to);
                dir.mkdirs();
                if (!f.createNewFile()) System.out.println("创建文件失败");
                from.transferTo(f);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return f;
    }
}
